
#include "icosahedron.h"

Icosahedron :: Icosahedron () : Polyhedra ()
{
	Icosahedron (this->Size());
}

Icosahedron :: Icosahedron (float _size) : Polyhedra (_size)
{
	Icosahedron (Size(), i, r);
}

Icosahedron :: Icosahedron (float _size, int _i, float _r) 
	: Polyhedra (_size, _i, _r)
{
	num_pts = 12;
	p = new Point[num_pts];
	SetPoint (_size);
}

Icosahedron :: ~Icosahedron ()
{
	Polyhedra::~Polyhedra();
	if (p)
		delete p;
}

void Icosahedron :: SetPoint (float _size)
{
	Polyhedra :: SetPoint (_size/2.0f);

	float phi = (float)(( 1.0f + sqrt(5.0f) ) / 2.0f);
	float a = (float)(1.0f / 1.5f);
	float b = (float)(1.0f / (1.5f * phi));

	p[0].SetPoint (0, b, -a);
	p[1].SetPoint (b, a, 0);
	p[2].SetPoint (-b, a, 0);
	p[3].SetPoint (0, b, a);
	p[4].SetPoint (0, -b, a);
	p[5].SetPoint (-a, 0, b);
	p[6].SetPoint (a, 0, b);
	p[7].SetPoint (0, -b, -a);
	p[8].SetPoint (a, 0, -b);
	p[9].SetPoint (-a, 0, -b);
	p[10].SetPoint (b, -a, 0);
	p[11].SetPoint (-b, -a, 0);
}

void Icosahedron :: _Draw (Point* pts)
{
	DrawFace (pts[0], pts[1], pts[2]);
	DrawFace (pts[3], pts[2], pts[1]);
	DrawFace (pts[3], pts[4], pts[5]);
	DrawFace (pts[3], pts[6], pts[4]);
	DrawFace (pts[0], pts[7], pts[8]);
	DrawFace (pts[0], pts[9], pts[7]);
	DrawFace (pts[4], pts[10], pts[11]);
	DrawFace (pts[7], pts[11], pts[10]);
	DrawFace (pts[2], pts[5], pts[9]);
	DrawFace (pts[11], pts[9], pts[5]);
	DrawFace (pts[1], pts[8], pts[6]);
	DrawFace (pts[10], pts[6], pts[8]);
	DrawFace (pts[3], pts[5], pts[2]);
	DrawFace (pts[3], pts[1], pts[6]);
	DrawFace (pts[0], pts[2], pts[9]);
	DrawFace (pts[0], pts[8], pts[1]);
	DrawFace (pts[7], pts[9], pts[11]);
	DrawFace (pts[7], pts[10], pts[8]);
	DrawFace (pts[4], pts[11], pts[5]);
	DrawFace (pts[4], pts[6], pts[10]);
}